#!/bin/bash

# My answer for:
# https://superuser.com/questions/248495/how-to-compare-mp3-flac-audio-data-in-a-file-ignoring-header-data-id3-tag-et/1219353#1219353
# https://superuser.com/questions/347141/identify-differences-between-mp3-files/1219360#1219360
: ${1?"Utility to compare *content* of mediafiles without metadata (id3 tags) consideration. Please provide 2 files for compare: `basename $0` original.mp3 possible-duplicate.mp3"}
: ${2?"Utility to compare *content* of mediafiles without metadata (id3 tags) consideration. Please provide 2 files for compare: `basename $0` original.mp3 possible-duplicate.mp3"}

# </dev/null absolutely required if you want use it in loop: https://unix.stackexchange.com/questions/36310/strange-errors-when-using-ffmpeg-in-a-loop/36411#36411
diff <( ffmpeg -loglevel panic -i "$1" -map_metadata -1 -f wav - </dev/null ) <( ffmpeg -loglevel panic -i "$2" -map_metadata -1 -f wav - </dev/null ) \
	|| echo "[$1] != [$2]"
